package com.yanqu.road.dao.impl.log;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.db.DbParameter;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.cricket.court.log.LogCricketCourtChangeScore;
import com.yanqu.road.entity.cricket.court.log.LogCricketCourtRoundRank;

import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LogCricketCourtChangeScoreDaoImpl extends TempDao {

    public boolean addLogCricketCourtChangeScoreList(List<LogCricketCourtChangeScore> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getCrossDb());
        String sql = "INSERT INTO t_c_log_cricket_court_change_score(serverId,userId,round,courtId,groupId,beforeScore,afterScore,beforeRank,afterRank,addTime) VALUES(?,?,?,?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogCricketCourtChangeScore data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, data.getServerId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getRound()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getCourtId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getGroupId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getBeforeScore()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getAfterScore()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getBeforeRank()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getAfterRank()));
            para.put(i++, new DbParameter(Types.DATE, data.getAddTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

}
